<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>定时任务新增页面</title>
    <!-- jquery -->
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <link rel="stylesheet" type="text/css" th:href="@{/css/animate.min.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap.min.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/css/font-awesome.min.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/css/mediaelementplayer.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/css/red.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/css/simple-line-icons.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/css/style.css}"/>
</head>
<body>
<div class="col-md-12 top-20 padding-0">
    <div class="col-md-12">
        <div class="panel">
            <div class="panel-body">
                <div class="panel-heading">
                    <h4>新增定时任务项</h4>
                </div>
                <div class="col-md-6" style="padding-left:10px;">
                    <form action="#" method="post">
                        <div class="form-group"><label class="col-sm-2 control-label text-right">任务编号:</label>
                            <div class="col-sm-10"><input type="text" name="taskno" id="taskno" class="form-control">
                            </div>
                        </div>
                        <br/> <br/> <br/>
                        <div class="form-group"><label class="col-sm-2 control-label text-right">任务名称:</label>
                            <div class="col-sm-10"><input type="text" name="taskname" id="taskname"
                                                          class="form-control"></div>
                        </div>
                        <br/> <br/>
                        <div class="form-group"><label class="col-sm-2 control-label text-right">定时配置规则:</label>
                            <div class="col-sm-10"><input type="text" placeholder="(例如: * /5 * * * * ? 每5秒执行一次)"
                                                          name="schedulerrule" id="schedulerrule" class="form-control">
                            </div>
                        </div>
                        <br/> <br/>
                        <div class="form-group"><label class="col-sm-2 control-label text-right">冻结状态:</label>
                            <div class="col-sm-10">
                                <select class="form-control" id="frozenstatus">
                                    <option th:value="FROZEN" selected="selected" disabled="disabled">冻结</option>
                                </select>
                            </div>
                        </div>

                        <br/> <br/>
                        <div class="form-group"><label class="col-sm-2 control-label text-right">执行方:</label>
                            <div class="col-sm-10"><input type="text" name="executorno" id="executorno"
                                                          class="form-control"></div>
                        </div>
                        <br/> <br/>
                        <div class="form-group"><label class="col-sm-2 control-label text-right">执行方式:</label>
                            <div class="col-sm-10">
                                <select class="form-control" id="sendtype">
                                    <option th:value="http" >http</option>
                                    <option th:value="kafka" >kafka</option>
                                </select>
                            </div>
                        </div>
                        <br/> <br/>
                        <div class="form-group"><label class="col-sm-2 control-label text-right">url:</label>
                            <div class="col-sm-10"><input type="text" name="url" id="url" class="form-control"></div>
                        </div>
                        <br/> <br/>
                        <div class="form-group"><label class="col-sm-2 control-label text-right">执行参数:</label>
                            <div class="col-sm-10"><input type="text" name="executeparamter" id="executeparamter"
                                                          class="form-control"></div>
                        </div>
                        <br/><br/>
                        <div class="form-group"><label class="col-sm-2 control-label text-right">timeKey:</label>
                            <div class="col-sm-10"><input type="text" placeholder="(例如: yyyy-MM-dd HH:mm:ss)"
                                                          name="timekey" id="timekey" class="form-control"></div>
                        </div>
                        <br/> <br/><br/>
                        <input type="button" class="btn btn-3d btn-danger" th:onclick="'history.go(-1);'" align="left"
                               style="float:left;margin-left:700px;" value="关闭"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="button" class="btn  btn-3d btn-success" id="savetask" align="right" value="保存"/>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript" th:inline="javascript">
    $(function () {
        $("#savetask").on('click', function (e) {
            var taskno = $("#taskno").val();
            var taskname = $("#taskname").val();
            var schedulerrule = $("#schedulerrule").val();
            var frozenstatus = $("#frozenstatus").val();
            var executorno = $("#executorno").val();
            var sendtype = $("#sendtype").val();
            var url = $("#url").val();
            var executeparamter = $("#executeparamter").val();
            var timekey = $("#timekey").val();
            $.ajax({
                url: "/quartz/add/task",
                dataType: "json",
                type: "POST",
                data: {
                    "taskno": taskno,
                    "taskname": taskname,
                    "schedulerrule": schedulerrule,
                    "frozenstatus": frozenstatus,
                    "executorno": executorno,
                    "sendtype": sendtype,
                    "url": url,
                    "executeparamter": executeparamter,
                    "timekey": timekey
                },
                success: function (result) {
                    if (result.code == 200) {
                        alert("添加成功!");
                        location.href = "/";
                    } else if (result.code == 1001) {
                        alert("该任务编号已经存在");
                    }
                    else {
                        alert("system error");
                    }
                }
            })
        });
    });
</script>
</body>
</html>
